/*******************************************************************************
* @file    fins_debug.c
* @author  Fins
* @brief   
* @time    2020-11-16 19:06:56 Monday
* @codeing UTF-8
* @license
*     Copyright 2020 Fins
*
*     Licensed under the Apache License, Version 2.0 (the "License");
*     you may not use this file except in compliance with the License.
*     You may obtain a copy of the License at
*
*         http://www.apache.org/licenses/LICENSE-2.0
*
*     Unless required by applicable law or agreed to in writing, software
*     distributed under the License is distributed on an "AS IS" BASIS,
*     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*     See the License for the specific language governing permissions and
*     limitations under the License.
* @verbatim
================================================================================
                        ##### xxxxxxxxxxxxxxxxxxxxxxx #####
================================================================================
* @endverbatim
* @attention
*******************************************************************************/



/* Includes start *************************************************************/
/*     Lib files ****************************** */

/*     User files ***************************** */
#include "../inc/fins_debug.h"

/* Includes end ***************************************************************/

/* Define start ***************************************************************/



/* Define end *****************************************************************/

/* Typedef start **************************************************************/



/* Typedef end ****************************************************************/

/* Global variable start ******************************************************/



/* Global Variable end ********************************************************/

/* Static function declaration start ******************************************/



/* Static function declaration end ********************************************/

/* function start *************************************************************/

/**
  * @brief      Output hex
  * @param[in]  tag: Debug tag
  * @param[in]  name: Array name
  * @param[in]  width: Out put width
  * @param[in]  buff: Data buff 
  * @param[in]  buffsize: Data buff size
  * @param[in]  file: File string
  * @param[in]  func: Function string
  * @param[in]  line: Line number
  * @param[out] var: Var brief
  * @retval     None
  */
void __FdbHex(
    const fuint8* tag, 
    const fuint8* name, 
    fuint8 width, 
    const fuint8* buff,
    fuint32 buffsize,
    const fuint8* file, 
    const fuint8* func, 
    fuint32 line) 
{
    FdbPrintf("[I@%d] %s: \r\n" ,line, tag);

    FdbPrintf("    %s[    -    ] |",name);
    for (fuint8 column = 0; column < width; column++)
    {
        FdbPrintf(" %02X",column);
        if ((column+1) % 8 == 0)
            FdbPrintf(" ");
    }
    FdbPrintf("\r\n");
    FdbPrintf("    %s------------|",name);
    for (fuint8 column = 0; column < width; column++)
    {
        FdbPrintf("---");
        if ((column+1) % 8 == 0)
            FdbPrintf("-");
    }
    FdbPrintf("\r\n");
    for (fuint32 row = 0; row * width < buffsize; row++)
    {
        FdbPrintf("    %s[%04X-%04X] |", name, row * width, (row + 1) * width -1);
        for (fuint8 column = 0; (column < width) && ((row) < (buffsize / width + (buffsize % width != 0))) ; column++)
        {
            if((row * width + column) < buffsize)
                FdbPrintf(" %02X",buff[row * width + column]);
            else
                FdbPrintf("   ");
            if ((column+1) % 8 == 0)
                FdbPrintf(" ");
        }
        FdbPrintf("    ");
        for (fuint8 column = 0; (column < width) && ((row * width + column) < buffsize) ; column++)
        {
            if( buff[row * width + column] < 32 || buff[row * width + column] > 126)
                FdbPrintf(".");
            else
                FdbPrintf("%c",buff[row * width + column]);
        }
        FdbPrintf("\r\n");
    }
}


/* function end ***************************************************************/

////////////////////////////////- END OF FILE  -////////////////////////////////
